package com.vehicle.comvehiclehealth;

import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.github.lzyzsd.circleprogress.DonutProgress;

/**
 * Created by cunguoyao on 2018-07-21.
 */

public class GuideFirstActivity extends BaseActivity {

    private TextView progressText;
    private ProgressBar progressBar1;
    private DonutProgress progressBar2;
    Handler handler = new Handler(){
        @Override
        public void handleMessage(final Message msg) {
            super.handleMessage(msg);
            progressBar1.setProgress(msg.arg1);
            progressBar2.setProgress(msg.arg1);
            progressText.setText(msg.arg1+"%");
            handler.postDelayed(updateProgress,100);
        }};

    Runnable updateProgress = new Runnable() {
        int i = 0;
        @Override
        public void run() {
            i+=1;
            Message message = handler.obtainMessage();
            message.arg1 = i;
            if(i<=100){
                handler.sendMessage(message);
            }
            if(i==100){
                handler.removeCallbacks(updateProgress);
            }
        }
    };

    private ImageView ivFinger;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide_first);
        initView();
        setTitle("心率血压测量");
        handler.postDelayed(updateProgress, 1000);

        TranslateAnimation translateAnimation = new TranslateAnimation(150f, 150f, 50, 150);
        translateAnimation.setDuration(2000);
        translateAnimation.setRepeatCount(Animation.INFINITE);
        translateAnimation.setRepeatMode(Animation.REVERSE);
        ivFinger.setAnimation(translateAnimation); //这里ivFinger就是我们要执行动画的item，例如一个imageView
        translateAnimation.start();
    }

    private void initView() {
        progressText = (TextView)findViewById(R.id.progress_text);
        progressBar1 = (ProgressBar)findViewById(R.id.progress1);
        progressBar2 = (DonutProgress) findViewById(R.id.progress2);
        ivFinger = (ImageView)findViewById(R.id.iv_finger);
    }
}
